<?php

error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING);

require_once 'include/inc.config.php';


require_once WACT_ROOT.'common.inc.php';
require_once WACT_ROOT.'controller/pathinfo.inc.php';
require_once APP_ROOT . 'model/common/user.php';
require_once APP_ROOT . 'model/common/session.php';

class RootAdminController extends PathInfoDispatchController {

	function RootAdminController() {
		parent::PathInfoDispatchController();
		@session_start();
		$this->addChild('myprofile',   new Handle(APP_CTRL_ROOT . 'pub/myprofile/pub.myprofile.index.php|MyprofileIndexPage'));
        $this->addChild('login',   new Handle(APP_CTRL_ROOT . 'pub/pub.login.php|LoginPage'));

		$this->registerOnActivateListener(new Delegate($this, 'check'));

	}

	function check(&$source, &$request, &$responseModel) {
		//print 'checking permissions...';

		$is_logged = Session::isLogin();
		if  (!$is_logged) {
			$this->setDefaultChild('login');
			return;
		}

        $user_id = Session::getUserId();
        $is_admin = User::isUserAdmin($user_id);
        $is_author = User::isUserArticleWriter($user_id);
        if  (!$is_admin && !$is_author) {
			$this->setDefaultChild('myprofile');
			return;
		}

		return;

	}

}


?>